package com.tuozixuan.codedemo.java9.flow;

import java.util.concurrent.Flow;
import java.util.concurrent.Flow.Subscriber;

public class IntPublisher implements Flow.Publisher<Integer> {

	/**
	 * 负责绑定Subscriber
	 */
	@Override
	public void subscribe(Subscriber<? super Integer> subscriber) {
        for(int i = 1; i <= 5; i++) {
            System.out.println("Publishing = " + i);
            // 将数据发给订阅者
            subscriber.onNext(i);
        }
        // 发出完成信号
        subscriber.onComplete();
	}

}
